package tpenchere.client.impl;

import java.util.ArrayList;
import java.util.EventListener;
import java.util.List;

import org.apache.log4j.Logger;
import org.omg.CORBA.Context;
import org.omg.CORBA.ContextList;
import org.omg.CORBA.DomainManager;
import org.omg.CORBA.ExceptionList;
import org.omg.CORBA.NVList;
import org.omg.CORBA.NamedValue;
import org.omg.CORBA.Object;
import org.omg.CORBA.Policy;
import org.omg.CORBA.Request;
import org.omg.CORBA.SetOverrideType;

import tpenchere.client.Client;
import tpenchere.client.ClientPOA;
import tpenchere.model.Enchere;

public class EnchereClientImpl extends ClientPOA implements EventListener {

	private static Logger log = Logger.getLogger(EnchereClientImpl.class);
	private List<PushListener> listeners = new ArrayList<PushListener>();

	public void push(Enchere enchere) {
		log.info("PUSH enchere");		
	}

	public void pushChannel(String channel) {
		log.info("PUSH occurred on channel \"" + channel + "\"");
		PushEvent event = new PushEvent(channel, this);
		for(PushListener pl : listeners) {
			// Update global subscribers and those who were specifically
			// listening on this channel
			if(pl.getChannel() == null || pl.getChannel().equals(channel)) {
				pl.update(event);				
			}
		}
	}
	
	public void addPushListener(PushListener listener) {
		listeners.add(listener);
	}
	
	public void removePushListener(PushListener listener) {
		listeners.remove(listener);
	}
}
